package src.dual_pointers;

import com.sun.tools.javac.Main;

import java.util.Arrays;
import java.util.Map;

/**
 * @author starsea
 * @date 2024-09-05 15:18
 */

public class Test14 {
    public static void main(String[] args) {
    int[][] points = {{10,16},{2,8},{1,6},{7,12}};
    int c=findMinArrowShots(points);
    }
    public static int findMinArrowShots(int[][] points) {
    int n=points.length;
    int[][] arr=new int[n][2];
        Arrays.sort(points,(a,b)->{
            return a[0]-b[0];
        });
        arr[0]=points[0];
        int j=0;
        for(int i=1;i<points.length;i++)
        {
            if(arr[j][0]<=points[i][0] && arr[j][1]>=points[i][0])
            {
                arr[j][0]= Math.max(points[i][0],arr[j][0]);
                arr[j][1]=Math.min(points[i][1],arr[j][1]);
            }else
            {
                j++;
                arr[j]=points[i];
            }
        }
        return j+1;
    }
}
